package spar.cancer;

import spar.cancer.config.CancerConfig;
import spar.cancer.data.from.ecxt.EcxtSocket;
import spar.cancer.data.to.dump.DumpFile;
import spar.cancer.data.to.grptrace.GrpTraceCSV;

import java.io.IOException;
import java.util.Date;
import java.util.List;

public class CancerTest2 {
    static CancerConfig getCancerConfig(List<Cancer<Double>> ecxtObjs) throws IOException {
        //init
        String timeStr = String.valueOf(new Date().getTime());
        CancerConfig config = new CancerConfig();
        config.codeFile = "src/test/java/spar/cancer/CancerTest2.java";
        config.kmeans = 3;
        config.dosThro = 0.5;
//        config.ecxt = new EcxtCSV("src/test/resources/data/data-1637930049.6603105.csv");
//        config.ecxt = new EcxtRedis("localhost", 6379);
        config.ecxt = new EcxtSocket(8080);
        config.ecxt.bind(ecxtObjs);
//        config.dump = new DumpRedis("localhost", 6311);
//        config.dump = new DumpStdout();
        config.dump = new DumpFile(timeStr + ".txt");
//        config.grpTrace = new GrpTraceDTrace(timeStr);
        config.grpTrace = new GrpTraceCSV(timeStr);
//        config.invGen = new InvGenDaikon(
//                "src/test/resources/util/daikon.jar", time);
        return config;
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        Cancer<Double> front = new Cancer<>("front");
        Cancer<Double> back = new Cancer<>("back");
        Cancer<Double> left = new Cancer<>("left");
        Cancer<Double> right = new Cancer<>("right");

        //init
        Cancer.Init(new CancerConfig("src/test/resources/cancer.conf"));
        //Cancer.Init(getCancerConfig(List.of(front, back, left, right)));

        //main iter loop
        while (Cancer.hasNextEcxtData()) {
            System.out.println("{" + front + "," + back + "," + left + "," + right + "}");
        }

        //func
        Cancer.grouping();
//        Cancer.invGen();

        //exit
        Cancer.Exit();
    }
}
